<?php
/**
 * Created by PhpStorm.
 * User: 共赢岛
 * Date: 2023/12/7
 * Time: 16:50
 */

namespace App\Services\LifeCycle;


use App\Admin\Services\CarService;
use App\Models\Brand;
use App\Models\Car;
use App\Models\CarPackage;
use App\Models\CarPackageCategory;

class BrandService
{
    public static function index($package_type = PACKAGE_TYPE_SALE)
    {
        $brand = Brand::where('status', DEFAULT_STATUS_SUCCESS)->get();

        foreach ($brand as $key => $value) {
            $package = CarPackage::where('brand_id', $value->id)
                ->where('type', $package_type)
                ->first();

            if (!$package) {
                unset($brand[$key]);
            }
        }

        if ($brand) {
            return $brand;
        }

        return false;
    }

    public static function one($brand_id)
    {
        $brand = Brand::find($brand_id);
        $brand->pic = path2url($brand->pic);

        return $brand;
    }
}